package indi.cc.demo.validator.handler;

import indi.cc.demo.validator.exception.BasicException;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.BindException;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.context.request.WebRequest;
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;

/**
 * ClassName: BaseExceptionHandler <br/><br/>
 * Description:
 *
 * @author SAP
 */
public class BaseExceptionHandler extends ResponseEntityExceptionHandler {
    @ExceptionHandler(BasicException.class)
    public ResponseEntity handleBasicException(final BasicException ex) {
        return new ResponseEntity(ex.getMessageList(), HttpStatus.BAD_REQUEST);
    }

    @Override
    protected ResponseEntity<Object> handleBindException(BindException ex, HttpHeaders headers, HttpStatus status, WebRequest request) {
        System.out.println("xxxxxxxxxxxxxx");
        return super.handleBindException(ex, headers, status, request);
    }
}
